package com.thitech.sif;

/**
 * 服务请求及返回报文存储类
 * 
 * @author shisheng.lian
 * @version v 1.1
 * @date 2014-08-06
 * */
public class ReqAndResContext {
	/**
	 * 当前用户线程，用于存储当前用户执行的报文结果
	 */
	private static final ThreadLocal<ReqAndResContext> reqAndResMessage = new ThreadLocal<ReqAndResContext>();
	private String request;
	private String response;

	/**
	 * 屏蔽无参构造方法，防止用户手工new对象，从而丢失ThreadLocal中的对象
	 */
	private ReqAndResContext() {
		super();
	}

	/**
	 * 获取当前线程中的ReqAndResContext，防止一个ThreadLocal中出现多个ReqAndResContext对象
	 * 
	 * @return
	 */
	public static ReqAndResContext currentContext() {
		ReqAndResContext currentContext = get();
		if (currentContext == null) {
			currentContext = new ReqAndResContext();
			set(currentContext);
		}
		return currentContext;
	}

	private static void set(ReqAndResContext sc) {
		reqAndResMessage.set(sc);
	}

	private static ReqAndResContext get() {
		return reqAndResMessage.get();
	}

	public static void remove() {
		reqAndResMessage.remove();
	}

	public String getRequest() {
		return request;
	}

	public void setRequest(String request) {
		this.request = request;
	}

	public String getResponse() {
		return response;
	}

	public void setResponse(String response) {
		this.response = response;
	}

}
